package com.iot.service.mqtt.handler;

import com.iot.service.mqtt.model.request.TlMqttHeartBeatReq;
import com.iot.service.mqtt.model.response.TlMqttHeartBeat;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.mqtt.MqttMessageType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @ClassName：ConnectHandler
 * @Author: hszhou
 * @Date: 2024/11/25 11:06
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@ChannelHandler.Sharable
@Component
public class TlMqttHeartBeatHandler extends SimpleChannelInboundHandler<TlMqttHeartBeatReq> {

    private static final  Logger logger = LoggerFactory.getLogger(TlMqttHeartBeatHandler.class);

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, TlMqttHeartBeatReq msg) throws Exception {
        logger.debug("in【PINGREQ】 handler");
        TlMqttHeartBeat res =TlMqttHeartBeat.of(MqttMessageType.PINGRESP);
        ctx.channel().writeAndFlush(res);
        logger.debug("build 【PINGRES】return");
    }
}
